package com.example.gamecenter.activitys

import ListRecommendAdapter
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.gamecenter.R
import com.example.gamecenter.adapter.ListHomeRecommendCardAdapter
import com.example.gamecenter.adapter.RecommendItem
import kotlinx.android.synthetic.main.activity_list.*

class ListActivity: AppCompatActivity() {
    private var list_adapter: ListRecommendAdapter?=null;
    private val context = this;

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        initView();
    }
    private fun initView(){
        val typeName = intent.getStringExtra("typeName")
        val typeId = intent.getIntExtra("typeId", 0);
        tv_list_title.text = typeName;

        // 初始化listview
        list_adapter  = ListRecommendAdapter(context)
        lv_list_view.adapter = list_adapter;
         getList(typeId)
        btn_back.setOnClickListener {
            finish();
        }
    }
    fun getList(typeId: Int?){
        val data: List<RecommendItem> = listOf(
            RecommendItem("标题1", "https://img.sxsme.com.cn/uploadimg/ico/2023/1007/1696665441196246.jpg",1, "天剑传说"),
            RecommendItem("标题2", "https://img.sxsme.com.cn/uploadimg/ico/2023/0228/1677552459611151.jpg",2, "天剑传说"),
            RecommendItem("标题3", "https://img.sxsme.com.cn/uploadimg/ico/2023/0228/1677552498848724.jpg",3, "天剑传说"),
            RecommendItem("标题4", "https://img.sxsme.com.cn/uploadimg/ico/2023/0228/1677552534375775.png",4, "天剑传说"),
            RecommendItem("标题5", "https://img.sxsme.com.cn/uploadimg/ico/2023/0228/1677552566865753.png",5, "天剑传说"),
            RecommendItem("标题6", "https://img.sxsme.com.cn/uploadimg/ico/2022/1214/1670986386653144.jpg",6, "天剑传说"),
            RecommendItem("标题7", "https://img.sxsme.com.cn/uploadimg/ico/2022/1214/1670986386653144.jpg",6, "天剑传说"),
            RecommendItem("标题8", "https://img.sxsme.com.cn/uploadimg/ico/2022/1214/1670986386653144.jpg",6, "天剑传说"),
        );
        list_adapter?.setDatas(data);
//        HiRetrofit.create(ApiService::class.java)
//            .getListByTypeId(typeId).enqueue(object : Callback<ApiResponse<List<RecommendItem>>> {
//                override fun onFailure(call: Call<ApiResponse<List<RecommendItem>>>, t: Throwable) {
//                    Log.e("study_fragment", t.message?:"unknown error")
//                }
//                override fun onResponse(
//                    call: Call<ApiResponse<List<RecommendItem>>>,
//                    response: Response<ApiResponse<List<RecommendItem>>>
//                ) {
//                    val data: List<RecommendItem>? = response.body()?.data;
//                    if (data != null) {
//                        list_adapter?.setDatas(data)
//                    }
//                }
//            })

    }
}